﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;

public partial class logon1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string str=RadioButtonList1.SelectedValue.ToString();
        //Response.Write(str);
        if (str == "1")
        {
            Panel1.Visible = true;
        }
        else 
        Panel1.Visible = false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string pass = Encrypt(TextBox3.Text, "litianping");
        DataClassesDataContext db = new DataClassesDataContext();
        db.insert_Member(TextBox1.Text, TextBox4.Text, TextBox7.Text, pass,TextBox8.Text);
        if (RadioButtonList1.SelectedValue.ToString() == "1")
        {
            //设置密保
            db.insert_Password(TextBox1.Text, DropDownList1.SelectedValue, TextBox5.Text, DropDownList2.SelectedValue, TextBox6.Text);
        }
        Response.Write("<script>alert('注册成功');location='logon.aspx'</script>");
    }
    public static string Encrypt(string Text, string sKey)
    {
        DESCryptoServiceProvider des = new DESCryptoServiceProvider();
        byte[] inputByteArray;
        inputByteArray = Encoding.Default.GetBytes(Text);
        des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
        des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
        cs.Write(inputByteArray, 0, inputByteArray.Length);
        cs.FlushFinalBlock();
        StringBuilder ret = new StringBuilder();
        foreach (byte b in ms.ToArray())
        {
            ret.AppendFormat("{0:X2}", b);
        }
        return ret.ToString();
    }
}